<template>
	<view>
		<u-tabs :list="list1" @click="click" lineColor='#FBE43F'
			:inactiveStyle="{ fontSize: '32rpx', transform: 'scale(1)',color: '#979797'  }"
			:activeStyle="{ color: '#000000',fontSize: '32rpx', }"></u-tabs>

		<scroll-view @scrolltolower="handleScrollToLower" class="ul" scroll-y :lower-threshold="300">
			<view class="li" v-for="(item,i) in tabList" :key="i" @click="goDetail(item)">
				<view class="dis aic ">
					<image :src="item.images" mode="aspectFit" class="goods_img"></image>
					<view class="">
						<view class="name">{{item.name}}</view>
						<view class="dis aic jcsb">
							<view class="fen">5500分</view>
							<view class="num">x1</view>
						</view>
					</view>
				</view>

				<view class="dis aic jcsb" style="margin-top: 20rpx;">
					<view class="btn1">实物</view>
					<view class="btn2" v-if="index == 2" @click="del(item)">删除</view>
					<view class="btn2" v-if="index == 1" @click="Signfor(item)">确认收货</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		pointsOrderList,
		pointsOrderDel,
		pointsOrderSignfor
	} from "@/api.js"
	export default {
		data() {
			return {
				index: 0,
				list1: [{
						name: '待发货',
					},
					{
						name: '已发货',
					}, {
						name: '已收货',
					}
				],
				pageNo: 1,
				pageSize: 10,
				total: 0,
				tabList: []
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			async del(item) {
				let res = await pointsOrderDel({
					id: item.id
				})
				if (res.code == 200) {
					uni.showToast({
						icon: "none",
						title: "删除成功"
					})
					this.reset()
				}
			},
			async Signfor(item) {
				let res = await pointsOrderSignfor({
					id: item.id
				})
				if (res.code == 200) {
					uni.showToast({
						icon: "none",
						title: "收货成功"
					})
					this.reset()
				}
			},


			init() {
				this.getList()
			},
			reset() {
				this.pageNo = 1
				this.pageSize = 10
				this.total = 0
				this.tabList = []
				this.getList()

			},
			handleScrollToLower() {
				let pageNo = this.pageNo
				let pageSize = this.pageSize
				let total = this.total
				console.log('一共' + total + '条，当前已经加载' + pageSize * pageNo + '条');
				if (total <= pageNo * pageSize) {
					console.log('已经到底了');
					return
				}
				uni.showLoading({
					title: '加载中'
				});
				this.pageNo++;
				this.getList();
				uni.hideLoading();
			},
			async getList() {
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				let res = await pointsOrderList({
					status: this.index,
					pageNo: this.pageNo,
					pageSize: this.pageSize
				})
				this.tabList = this.tabList.concat(res.result.records)
				this.total = res.result.total

				uni.hideLoading();

			},

			click(item) {
				this.index = item.index
				this.reset()
			},
			goDetail(item) {
				uni.navigateTo({
					url: '/pages/shop/pointsOrderDetails?id=' + item.id
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.ul {
		height: calc(100vh - 88rpx);
		background: #f8f8f8;

		padding-bottom: 60rpx;
		box-sizing: border-box;

		.li {
			width: 690rpx;
			height: 320rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(204, 184, 184, 0.12);
			border-radius: 11rpx 11rpx 11rpx 11rpx;
			padding: 22rpx 16rpx;
			box-sizing: border-box;
			margin: 20rpx auto;

			.goods_img {
				max-width: 260rpx;
				margin-right: 20rpx;
				max-height: 200rpx;
			}

			.name {
				font-family: Roboto Mono, Roboto Mono;
				font-weight: 300;
				font-size: 33rpx;
				color: #000000;
				margin-bottom: 60rpx;
			}

			.fen {
				font-family: Roboto, Roboto;
				font-weight: 400;
				font-size: 29rpx;
				color: #FF7373;
			}

			.num {
				font-family: Roboto, Roboto;
				font-weight: 400;
				font-size: 24rpx;
				color: #656565;
			}

			.btn1 {
				font-family: Roboto, Roboto;
				font-weight: 400;
				font-size: 25rpx;
				color: #A4A4A4;
			}

			.btn2 {
				width: 132rpx;
				height: 60rpx;
				line-height: 60rpx;
				background: #FF9C06;
				border-radius: 1812rpx 1812rpx 1812rpx 1812rpx;
				font-family: Roboto, Roboto;
				font-weight: 500;
				font-size: 22rpx;
				color: #FFFFFF;
				text-align: center;
			}
		}
	}
</style>